import pymysql

from pyecharts import options
from pyecharts.charts import Pie

#创建数据库连接
db = pymysql.connect(
     host='localhost',
     port=3306,
    database='crawlerdemo',
     user='root',
     passwd='123456',
     charset='utf8'
 )
curses = db.cursor();
sql  = "select job_place,count(job_id)*100.0/(select count(*) from job) as percentage from job group by job_place order by percentage desc"

try:
    curses.execute(sql)
    res = curses.fetchall()
    pie = Pie()
    #[("类型1",30)("类型2",4日),......
    pie.add("单位/个",res)
    pie.set_global_opts(title_opts=options.TitleOpts(title="各城市岗位量占比"))
    pie.render("piera.html")
except Exception as e:
    print("查询出了问题")
